package cn.hua.trip.admin.controller;

import cn.hua.trip.admin.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import java.util.HashMap;

@RestController
@RequestMapping("/uploadImges")
public class ImageController {

    @Autowired
    private ServletContext ctx;

  /*  @PostMapping
    public Object uploadImage(MultipartFile upload){
        //要得到的数据为{"url":"/upload/xxx.jpg","status:1"}这种格式的数据
        HashMap<Object, Object> map = new HashMap<Object,Object>();

        try{
            //成功
            String imagePath = UploadUtil.upload(upload,UploadUtil.IMG_BASE_PATH+"upload");
            map.put("url",imagePath);
            map.put("status",1);
        }catch (Exception e){
            //失败
            e.printStackTrace();
            map.put("url","");
            map.put("status",0);
        }
        return map;
    }*/
}
